<?php
	/**
	* Products Hot Widget
	* 
	* @author trungdt
	* @since Oct 17, 2011
	*/
	if (!defined('EXPONENT')) exit('');
	
	$temp=serialize($loc);
	
	// get module config
	$config=$db->selectObject("productsmodule_config", "location_data = '{$temp}'");
	
	$min=0; $max=0;
	
	// for hot product
	$product_hot=$db->selectObjects("productsmodule_products", "location_data = '{$temp}' AND (public_state = 1) AND hot_product = 1 ORDER BY post_date DESC, stars DESC LIMIT 0, 12");
	$product_hot = productsmodule::__ProductProcess($product_hot, $config,$max, $min, false );
	// for sale
	$product_sale=$db->selectObjects("productsmodule_products", "location_data = '{$temp}' AND (public_state = 1) AND on_sale = 1 ORDER BY post_date DESC, stars DESC  LIMIT 0, 12");
	$product_sale = productsmodule::__ProductProcess($product_sale, $config,$max, $min, false );
	// for best_seller
	$product_best_seller=$db->selectObjects("productsmodule_products", "location_data = '{$temp}' AND (public_state = 1) AND best_seller = 1 ORDER BY post_date DESC, stars DESC LIMIT 0, 12");
	$product_best_seller = productsmodule::__ProductProcess($product_best_seller, $config,$max, $min, false );
	// for products new
	$product_new=$db->selectObjects("productsmodule_products", "location_data = '{$temp}' AND (public_state = 1) ORDER BY post_date DESC, stars DESC LIMIT 0, 12");
	$product_new = productsmodule::__ProductProcess($product_new, $config,$max, $min, false );
	
	// fetch to template
	$template=new template("productsmodule","_Widget_ProductHot",$loc);
	$template->register_permissions(array('administrate',"configure", "create", "edit", "delete"),$loc);
	
	$template->assign("product_hot", $product_hot);
	$template->assign("product_hot_count", count($product_hot));
	
	$template->assign("product_sale", $product_sale);
	$template->assign("product_sale_count", count($product_sale));
	
	$template->assign("product_best_seller", $product_best_seller);
	$template->assign("product_best_seller_count", count($product_best_seller));
	
	$template->assign("product_new", $product_new);
	$template->assign("product_new_count", count($product_new));
	
	$template->output();

?>
